﻿#region License
// Copyright (c) 2009 Shun Chi Guo
// E-Mail:shuncy@gmail.com
// Blog:http://shuncy.cnblogs.com
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
using System.Text;

namespace shun.PAPLib
{
    /// <summary>
    /// WapPush调用请求包
    /// </summary>
    public class RequestPackge
    {
        private List<string> lsAddress = new List<string>();
        /// <summary>
        /// 接收地址信息
        /// </summary>
        public List<string> Address
        {
            get { return lsAddress; }
            set 
            {
                lsAddress.Clear();
                foreach (string val in value)
                {
                    string phone = ParseNum(val);
                    if (phone != String.Empty)
                    {
                        lsAddress.Add("wappush=" + phone +"/type=PLMN@ppg.operator.com");
                    }
                }
            }
        }
        /// <summary>
        /// 检查及转换号码为标准格式
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        private string ParseNum(string phone)
        {
            if (!phone.StartsWith("+86") && phone.Length == 11)
            {
                phone = "+86" + phone;
            }
            else if(!(phone.Length == 14))
            {
                phone = String.Empty;
            }
            return phone;
        }
        /// <summary>
        /// 一个连接地址数组，当ContentType为Url时有效
        /// </summary>
        public string Url { get; set; }
        /// <summary>
        /// 在指定的时间才能发送，定时时间，格式YYYY-MM-DDThh:mm:ssZ 
        /// </summary>
        public DateTime DeliverAfterTimestamp { get; set; }
        /// <summary>
        /// 内容类型，可以为Url或Content
        /// </summary>
        public string ContentType { get; set; }
        /// <summary>
        /// 实际的内容，当ContentType为Content时有效，是一个格式化的Xml文档
        /// </summary>
        public string Content { get; set; }
        

    }
}
